public class MaxProduct {
    public static void main(String[] args) {
        MaxProduct  max= new MaxProduct();
        int[] nums = {2,3,-2,4};
        int i = max.maxProduct(nums);
        System.out.println(i);
    }
    public int maxProduct(int[] nums) {
        // 子问题 ，求i的最大以及最小子序列问题
        // 状态数组 两个一维数组
        // dp方程 f(i) = max(f(n-1),1)*a[i];f(i) = min(f(n-1),1)*a[i];
        int max = nums[0];
        int[] oneNums = new int[nums.length];
        int[] twoNums = new int[nums.length];
        for(int i=0;i<nums.length;i++){
            oneNums[i] = Math.max(twoNums[i-1],Math.max(oneNums[i-1],1))*nums[i];
            twoNums[i] = Math.min(twoNums[i-1],Math.min(oneNums[i-1],1))*nums[i];
            max = Math.max(max,Math.max(oneNums[i],twoNums[i]));
        }
        return max;
    }
}
